﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>您正在做的业务是:人力资源--调动管理--调动审核</title>
    <!-- 引入样式 -->

    <script src="~/lib/vue.global.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css">
    <script src="//unpkg.com/element-plus"></script>

    <style>
        a {
            text-decoration: none; /* 去除下划线 */
        }
        /* 添加页面背景色 */
        body {
            background-color: #FFFFCC; /* 示例浅灰色，可替换为你的图片主色值 */
        }

        .el-table {
            background-color: white; /* 表格白底，与背景色区分 */
        }

        .transfer-registration {
            padding: 10px;
        }

        .business-title {
            font-size: 14px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .button-group {
            text-align: right;
            margin-bottom: 10px;
        }

        .form-table {
            width: 100%;
            border-collapse: collapse;
        }

            .form-table td {
                border: 1px solid #000;
                padding: 5px;
            }

        .label {
            background-color: #FFD553; /* 模拟表头黄色背景 */
            text-align: right;
            font-weight: bold;
        }

        .vertical-top {
            vertical-align: top;
        }

        input, select, textarea {
            width: 100%;
            box-sizing: border-box;
        }

            input[disabled], textarea[disabled] {
                background-color: #f0f0f0;
            }

    </style>

</head>
<body>

    <div class="transfer-registration">
        <!-- 业务标题 -->
        <div class="business-title">您正在做的业务是:人力资源--调动管理--调动审核</div>
        <!-- 操作按钮 -->
        <div class="button-group">

            <div style="display: inline-block; margin-right: 20px;">

                <el-radio v-model="form.approvalStatus" label="1">通过</el-radio>
                <el-radio v-model="form.approvalStatus" label="0">不通过</el-radio>

            </div>

            <el-button type="primary" v-on:click="handleSubmit">提交</el-button>
            <el-button v-on:click="handleReturn">返回</el-button>
        </div>
        <!-- 主体表格 -->
        <form>
            <table class="form-table">
                <tr>
                    <td class="label">档案编号</td>
                    <td><el-input v-model="form.human_id" readonly></el-input></td>
                    <td class="label">姓名</td>
                    <td><el-input v-model="form.human_name" readonly></el-input></td>
                    <td class="label">原薪酬标准</td>
                    <td><el-input v-model="form.original_salary_standard_name" readonly></el-input></td>
                    <td class="label">原薪酬总额</td>
                    <td><el-input v-model="form.original_salary_total" readonly></el-input></td>
                </tr>
                <tr>
                    <td class="label">原一,二，三级机构</td>
                    <td colspan="4">
                        <el-cascader v-model="originalOrg"
                                     :options="orgOptions"
                                     :props="cascaderProps"
                                     disabled
                                     class="w-full">
                        </el-cascader>
                    </td>
                    <td class="label">原职位分类和原职位名称</td>
                    <td colspan="4">
                        <el-cascader v-model="originalJob"
                                     :options="jobOptions"
                                     :props="jobCascaderProps"
                                     disabled
                                     class="w-full">
                        </el-cascader>
                    </td>
                </tr>
                <tr>
                    <td class="label">新一,二，三级机构名称</td>
                    <td colspan="4">
                        <el-cascader v-model="selectedOrg"
                                     :options="orgOptions"
                                     :props="cascaderProps"
                                     placeholder="请选择机构"
                                     clearable
                                     v-on:change="handleOrgChange"
                                     class="w-full"
                                     style="width: 100%;">
                        </el-cascader>
                    </td>
                    <td class="label">新职位分类和新职位名称</td>
                    <td colspan="4">
                        <el-cascader v-model="selectedJob"
                                     :options="jobOptions"
                                     :props="jobCascaderProps"
                                     placeholder="请选择职位分类和职位"
                                     clearable
                                     v-on:change="handleJobChange"
                                     class="w-full"
                                     style="width: 100%;">
                        </el-cascader>
                    </td>
                </tr>
                <tr>
                    <td class="label">新薪酬标准</td>
                    <td>
                        <el-select v-model="form.new_salary_standard_id"
                                   placeholder="------请选择------"
                                   v-on:click="handleSalaryChange">
                            <el-option v-for="option in salaryStandards"
                                       :key="option.value"
                                       :label="option.label"
                                       :value="option.value" />
                        </el-select>
                        @* <el-input v-model="form.new_salary_standard_name" readonly></el-input> *@
                    </td>
                    <td class="label">新薪酬总额</td>
                    <td><el-input v-model="form.new_salary_total"></el-input></td>
                    <td class="label">登记人</td>
                    <td><el-input v-model="form.registrant" readonly></el-input></td>
                    <td class="label">登记时间</td>
                    <td>
                        <el-input type="text" v-model="form.registration_time" readonly></el-input>
                    </td>
                </tr>
                <tr>
                    <td class="label">复核人</td>
                    <td colspan="3"><el-input v-model="form.checkr" readonly></el-input></td>
                    <td class="label">复核时间</td> 
                    <td colspan="3">
                        <el-input type="text" v-model="form.check_time" readonly></el-input>
                    </td>
                </tr>
                <tr>
                    <td class="label vertical-top">调动原因</td>
                    <td colspan="7">
                        <el-input v-model="form.change_reason" type="textarea" :rows="4" />
                        @* <textarea v-model="form.transfer_reason" :rows="4"></textarea> *@
                    </td>
                </tr>
                <tr>
                    <td class="label vertical-top">复核通过意见</td>
                    <td colspan="7">
                        <el-input v-model="form.check_reason" type="textarea" :rows="4" />
                        @* <textarea v-model="form.check_status" :rows="4"></textarea> *@
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <script type="text/javascript">
        const { createApp, ref, onMounted, reactive } = Vue;
        const { ElMessage } = ElementPlus;

        const app = createApp({
            setup() {
                // 表单数据 - 包含原数据和新数据
                const form = reactive({
                    // 基础信息
                    id: '',
                    human_id: '',
                    human_name: '',
                    human_id_card: '',

                    // 原机构信息
                    original_first_kind_id: 0,
                    original_first_kind_name: '',
                    original_second_kind_id: 0,
                    original_second_kind_name: '',
                    original_third_kind_id: 0,
                    original_third_kind_name: '',

                    // 原职位信息
                    original_job_category_id: 0,
                    original_job_category_name: '',
                    original_job_id: 0,
                    original_job_name: '',

                    // 原薪酬信息
                    original_salary_standard_id: '',
                    original_salary_standard_name: '',
                    original_salary_total: 0,

                    // 新机构信息
                    new_first_kind_id: 0,
                    new_first_kind_name: '',
                    new_second_kind_id: 0,
                    new_second_kind_name: '',
                    new_third_kind_id: 0,
                    new_third_kind_name: '',

                    // 新职位信息
                    new_job_category_id: 0,
                    new_job_category_name: '',
                    new_job_id: 0,
                    new_job_name: '',

                    // 新薪酬信息
                    new_salary_standard_id: '',
                    new_salary_standard_name: '',
                    new_salary_total: 0,

                    // 登记信息
                    registrant: '',
                    registration_time: '',

                    // 审核信息
                    checkr: '',
                    check_time: '',
                    check_status: '',


                    change_reason: '',
                    check_reason: '',

                    approvalStatus:'1', // 审核状态：1-通过，0-不通过，默认通过
                });

                // 原机构级联选择
                const originalOrg = ref([]); // 原机构ID数组 [一级ID, 二级ID, 三级ID]

                // 原职位级联选择
                const originalJob = ref([]); // 原职位ID数组 [分类ID, 职位ID]

                // 新机构级联选择
                const selectedOrg = ref([]); // 选中的新机构ID数组

                // 新职位级联选择
                const selectedJob = ref([]); // 选中的新职位ID数组

                // 机构级联数据
                const orgOptions = ref([]);
                const cascaderProps = ref({
                    expandTrigger: 'click',
                    value: 'id',
                    label: 'name',
                    children: 'children',
                    checkStrictly: false,
         
                });

                // 职位级联数据
                const jobOptions = ref([]);
                const jobCascaderProps = ref({
                    expandTrigger: 'click',
                    value: 'id',
                    label: 'name',
                    children: 'children',
                    checkStrictly: false
                });

                // 薪酬标准数据
                const salaryStandards = ref([]);

                // 获取机构级联数据
                const fetchOrgData = async () => {
                    try {
                                const response = await axios.get('/FirstLevelCX');
                        orgOptions.value = response.data;
                        console.log('机构级联数据加载成功', orgOptions.value);
                    } catch (error) {
                        console.error('获取机构数据失败:', error);
                        ElMessage.error('获取机构数据失败，请重试');
                    }
                };

                // 获取职位级联数据
                const fetchJobData = async () => {
                    try {
                                const response = await axios.get('/JobCategoryCX');
                        jobOptions.value = response.data;
                        console.log('职位级联数据加载成功', jobOptions.value);
                    } catch (error) {
                        console.error('获取职位数据失败:', error);
                        ElMessage.error('获取职位数据失败，请重试');
                    }
                };

                // 获取薪酬标准数据
                const fetchSalaryStandards = async () => {
                    try {
                        const response = await axios.get('/DDDJ/XCBD');
                        if (response.data) {
                            salaryStandards.value = response.data;
                            console.log('薪酬标准数据加载成功', salaryStandards.value);
                        } else {
                            ElMessage.warning('获取薪酬标准数据为空');
                        }
                    } catch (error) {
                        console.error('获取薪酬标准数据失败:', error);
                        ElMessage.error('获取薪酬标准数据失败，请重试');
                    }
                };

                // 处理新机构级联选择变化
                const handleOrgChange = (value) => {
                    // 清空名称
                    form.new_first_kind_name = form.new_second_kind_name = form.new_third_kind_name = '';

                    // 处理I级
                    if (value[0]) {
                        const firstNode = orgOptions.value.find(node => node.id === value[0]);
                        if (firstNode) {
                            form.new_first_kind_name = firstNode.name;
                            form.new_first_kind_id = value[0];

                            // 处理II级
                            if (value[1]) {
                                const secondNode = firstNode.children.find(node => node.id === value[1]);
                                if (secondNode) {
                                    form.new_second_kind_name = secondNode.name;
                                    form.new_second_kind_id = value[1];

                                    // 处理III级
                                    if (value[2]) {
                                        const thirdNode = secondNode.children.find(node => node.id === value[2]);
                                        form.new_third_kind_name = thirdNode?.name || '';
                                        form.new_third_kind_id = value[2];
                                    }
                                }
                            }
                        }
                    }
                };

                // 处理新职位级联选择变化
                const handleJobChange = (value) => {
                    // 清空名称
                    form.new_job_category_name = form.new_job_name = '';

                    // 处理职位分类（第1级）
                    if (value[0]) {
                        const categoryNode = jobOptions.value.find(node => node.id === value[0]);
                        if (categoryNode) {
                            form.new_job_category_name = categoryNode.name;
                            form.new_job_category_id = value[0];

                            // 处理职位名称（第2级）
                            if (value[1]) {
                                const jobNode = categoryNode.children.find(node => node.id === value[1]);
                                form.new_job_name = jobNode?.name || '';
                                form.new_job_id = value[1];
                            }
                        }
                    }
                };

                // 处理薪酬选择变化
                const handleSalaryChange = (value) => {
                    const selectedOption = salaryStandards.value.find(option => option.value === value);
                    if (selectedOption) {
                        form.new_salary_standard_id = value;
                        form.new_salary_standard_name = selectedOption.label;
                    } else {
                        form.new_salary_standard_id = '';
                        form.new_salary_standard_name = '';
                    }
                };

                // 从URL获取id
                const getUrlId = () => {
                    const urlParams = new URLSearchParams(window.location.search);
                    const id = urlParams.get('id');
                    console.log('接收到的ID值:', id);
                    return id;
                };

                // 根据id获取调动记录数据
                const fetchOriginalData = async (id) => {
                    if (id) {
                        try {
                            const response = await axios.get(`/DDSH/Update1/?id=${id}`);
                            const data = response.data.data;

                            if (data) {
                                // 填充基础信息
                                form.id = data.mch_id;
                                form.human_id = data.human_id;
                                form.human_name = data.human_name;
                                form.human_id_card = data.human_id_card;

                                // 填充原机构信息
                                form.original_first_kind_id = data.original_first_kind_id;
                                form.original_first_kind_name = data.original_first_kind_name;
                                form.original_second_kind_id = data.original_second_kind_id;
                                form.original_second_kind_name = data.original_second_kind_name;
                                form.original_third_kind_id = data.original_third_kind_id;
                                form.original_third_kind_name = data.original_third_kind_name;
                                originalOrg.value = [
                                    data.original_first_kind_id,
                                    data.original_second_kind_id,
                                    data.original_third_kind_id
                                ];
                                 
       

                                // 填充原职位信息
                                form.original_job_category_id = data.original_job_category_id;
                                form.original_job_category_name = data.original_job_category_name;
                                form.original_job_id = data.original_job_id;
                                form.original_job_name = data.original_job_name;
                                originalJob.value = [
                                    data.original_job_category_id,
                                    data.original_job_id
                                ];

                                // 填充原薪酬信息
                                form.original_salary_standard_id = data.original_salary_standard_id;
                                form.original_salary_standard_name = data.original_salary_standard_name;
                                form.original_salary_total = data.original_salary_total;

                                // 填充新机构信息
                                form.new_first_kind_id = data.new_first_kind_id;
                                form.new_first_kind_name = data.new_first_kind_name;
                                form.new_second_kind_id = data.new_second_kind_id;
                                form.new_second_kind_name = data.new_second_kind_name;
                                form.new_third_kind_id = data.new_third_kind_id;
                                form.new_third_kind_name = data.new_third_kind_name;


                                selectedOrg.value = [
                                    data.new_first_kind_id,
                                    data.new_second_kind_id,
                                    data.new_third_kind_id
                                ];

                              

                                // 填充新职位信息
                                form.new_job_category_id = data.new_job_category_id;
                                form.new_job_category_name = data.new_job_category_name;
                                form.new_job_id = data.new_job_id;
                                form.new_job_name = data.new_job_name;
                                selectedJob.value = [
                                    data.new_job_category_id,
                                    data.new_job_id
                                ];

                                // 填充新薪酬信息
                                form.new_salary_standard_id = data.new_salary_standard_id;
                                form.new_salary_standard_name = data.new_salary_standard_name;
                                form.new_salary_total = data.new_salary_total;

                                // 填充登记和审核信息
                                form.registrant = data.registrant;
                                form.registration_time = data.registration_time;

                                       // 替换为：
                                form.checkr = data.checkrName; // 从接口返回的数据中获取

                                form.check_time = data.check_time;
                                form.check_status = data.check_status;
                                form.change_reason = data.change_reason;

                                form.check_reason=data.check_reason;

                                console.log('原职位调动表数据数据填充成功', data);
                            }
                        } catch (error) {
                            console.error('获取数据失败:', error);
                            ElMessage.error('获取数据失败，请重试');
                        }
                    }
                };

                // 返回上一页
                const handleReturn = () => {
                    window.location.href = '/DDSH/SHYM';
                };


                // 初始化时设置当前时间
                const updateTime = () => {
                    const now = new Date();
                    const formattedTime = now.toISOString().split('T')[0] + ' ' + now.toTimeString().split(' ')[0];
                    form.check_time = formattedTime;
                };


                // 提交表单
                const handleSubmit = async () => {

                      // 获取审核状态
                    const isApproved = form.approvalStatus === '1';

                    // 验证复核人是否填写
                    if (!form.checkr) {
                        ElMessage.error('请填写复核人');
                        return;
                    }

                    // 根据审核状态执行不同的验证
                    if (isApproved) {
                        // 审核通过的情况
                        if (!form.check_reason) {
                            ElMessage.error('审核通过时请填写复核通过意见');
                            return;
                        }

                        // 调用审核通过的方法
                        await handleApproval();
                    } else {
                        // 审核不通过的情况
                        // 不需要验证复核通过意见，但可以添加其他验证

                        // 调用审核不通过的方法
                        await handleRejection();
                    }


                };



                // 审核通过的处理方法
                const handleApproval = async () => {
                      const fhsj=new Date().toISOString();

                        // 构造审核通过的提交数据
                        const submitData = {
                            mch_id: form.id, //主键
                            check_time: fhsj, //复核时间
                            checker: form.checkr, //复核人
                            check_reason:form.check_reason,// 复核通过意见
                            check_status:form.approvalStatus, //复核通过状态

                        };

                        console.log('审核通过提交数据:', submitData);

                        // 调用后端审核通过的API
                        const response = await axios.post('/DDSH/Approval', submitData);

                        if (response.data.success) {
                            ElMessage.success('审核通过成功');
                            window.setTimeout(() => {
                                window.location.href = '/DDSH/CGZS';
                            }, 1500);
                        } else {
                            ElMessage.error(response.data.message || '审核通过失败');
                        }

                };


                 // 审核不通过的处理方法
                const handleRejection = async () => {

                     const fhsj1=new Date().toISOString();

                        // 构造审核不通过的提交数据
                        const submitData = {
                            mch_id: form.id,
                            check_time: fhsj1, //复核时间
                            checker: form.checkr, //复核人
                            check_status:form.approvalStatus, //复核通过状态

                        };

                        console.log('审核不通过提交数据:', submitData);

                        // 调用后端审核不通过的API
                        const response = await axios.post('/DDSH/Rejection', submitData);

                        if (response.data.success) {
                            ElMessage.success('审核不通过成功');
                            window.setTimeout(() => {
                                window.location.href = '/DDSH/BTZS';
                            }, 1500);
                        } else {
                            ElMessage.error(response.data.message || '审核不通过失败');
                        }

                };



// 页面初始化
onMounted(async () => {
  const id = getUrlId();
  // 严格保证加载顺序
  await fetchOrgData();       // 1. 先加载机构数据
  await fetchJobData();       // 2. 加载职位数据
  await fetchSalaryStandards();// 3. 加载薪酬数据
  await fetchOriginalData(id); // 4. 最后加载原始数据
  updateTime();
  setInterval(updateTime, 1000);
});



              

                return {
                    form,
                    originalOrg,
                    originalJob,
                    selectedOrg,
                    selectedJob,
                    orgOptions,
                    jobOptions,
                    cascaderProps,
                    jobCascaderProps,
                    handleOrgChange,
                    handleJobChange,
                    salaryStandards,
                    handleSalaryChange,
                    handleReturn,
                    handleSubmit
                };
            }
        });

        app.use(ElementPlus).mount('.transfer-registration');
    </script>

</body>
</html> 